﻿using System;
using VideoServices.Domain.DAL;
using VideoServices.Domain.Entities;

namespace VideoServices.Business
{
    public class StoreBusinessObject
    {
        #region Fields

        private readonly IStoreDataAccess storeDao;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="StoreBusinessObject"/> class.
        /// </summary>
        public StoreBusinessObject()
        {
            storeDao = new StoreDataAccess();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="StoreBusinessObject"/> class.
        /// </summary>
        /// <param name="dao">The DAO.</param>
        public StoreBusinessObject(IStoreDataAccess dao)
        {
            // This constructor enables easy TDD as it takes in whatever IStoreDataAccess implementation.
            storeDao = dao;
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Gets the store by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Store GetStoreById(int id)
        {
            Store store;
            try
            {
                store = storeDao.GetStoreById(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return store;
        }

        /// <summary>
        /// Creates the store.
        /// </summary>
        /// <param name="newStore">The new store.</param>
        /// <returns></returns>
        public Store CreateStore(Store newStore)
        {
            Store store;
            try
            {
                store = storeDao.CreateStore(newStore);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return store;
        }

        #endregion
    }
}
